using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace LMSData
{
    /// <summary>
    /// Controller class for UserProfile
    /// </summary>
    [System.ComponentModel.DataObject]
    public partial class UserProfileController
    {
        // Preload our schema..
        UserProfile thisSchemaLoad = new UserProfile();
        private string userName = string.Empty;
        protected string UserName
        {
            get
            {
				if (userName.Length == 0) 
				{
    				if (System.Web.HttpContext.Current != null)
    				{
						userName=System.Web.HttpContext.Current.User.Identity.Name;
					}

					else
					{
						userName=System.Threading.Thread.CurrentPrincipal.Identity.Name;
					}

				}

				return userName;
            }

        }

        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public UserProfileCollection FetchAll()
        {
            UserProfileCollection coll = new UserProfileCollection();
            Query qry = new Query(UserProfile.Schema);
            coll.LoadAndCloseReader(qry.ExecuteReader());
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public UserProfileCollection FetchByID(object UserProfileID)
        {
            UserProfileCollection coll = new UserProfileCollection().Where("UserProfileID", UserProfileID).Load();
            return coll;
        }

		
		[DataObjectMethod(DataObjectMethodType.Select, false)]
        public UserProfileCollection FetchByQuery(Query qry)
        {
            UserProfileCollection coll = new UserProfileCollection();
            coll.LoadAndCloseReader(qry.ExecuteReader()); 
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public bool Delete(object UserProfileID)
        {
            return (UserProfile.Delete(UserProfileID) == 1);
        }

        [DataObjectMethod(DataObjectMethodType.Delete, false)]
        public bool Destroy(object UserProfileID)
        {
            return (UserProfile.Destroy(UserProfileID) == 1);
        }

        
        
    	
	    /// <summary>
	    /// Inserts a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Insert, true)]
	    public void Insert(int UserID,string FirstName,string MiddleName,string LastName,string Address,string City,string StateProvince,string Country,string PostalCode,string Title,string JobCode,string CostCenter,string UniqueID,string Telephone,string CellPhone,string Email,DateTime? LastUpdatedDate,DateTime? CreatedOn,string CreatedBy,DateTime? ModifiedOn,string ModifiedBy,bool IsDeleted)
	    {
		    UserProfile item = new UserProfile();
		    
            item.UserID = UserID;
            
            item.FirstName = FirstName;
            
            item.MiddleName = MiddleName;
            
            item.LastName = LastName;
            
            item.Address = Address;
            
            item.City = City;
            
            item.StateProvince = StateProvince;
            
            item.Country = Country;
            
            item.PostalCode = PostalCode;
            
            item.Title = Title;
            
            item.JobCode = JobCode;
            
            item.CostCenter = CostCenter;
            
            item.UniqueID = UniqueID;
            
            item.Telephone = Telephone;
            
            item.CellPhone = CellPhone;
            
            item.Email = Email;
            
            item.LastUpdatedDate = LastUpdatedDate;
            
            item.CreatedOn = CreatedOn;
            
            item.CreatedBy = CreatedBy;
            
            item.ModifiedOn = ModifiedOn;
            
            item.ModifiedBy = ModifiedBy;
            
            item.IsDeleted = IsDeleted;
            
	    
		    item.Save(UserName);
	    }

    	
	    /// <summary>
	    /// Updates a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
	    public void Update(int UserProfileID,int UserID,string FirstName,string MiddleName,string LastName,string Address,string City,string StateProvince,string Country,string PostalCode,string Title,string JobCode,string CostCenter,string UniqueID,string Telephone,string CellPhone,string Email,DateTime? LastUpdatedDate,DateTime? CreatedOn,string CreatedBy,DateTime? ModifiedOn,string ModifiedBy,bool IsDeleted)
	    {
		    UserProfile item = new UserProfile();
		    
				item.UserProfileID = UserProfileID;
				
				item.UserID = UserID;
				
				item.FirstName = FirstName;
				
				item.MiddleName = MiddleName;
				
				item.LastName = LastName;
				
				item.Address = Address;
				
				item.City = City;
				
				item.StateProvince = StateProvince;
				
				item.Country = Country;
				
				item.PostalCode = PostalCode;
				
				item.Title = Title;
				
				item.JobCode = JobCode;
				
				item.CostCenter = CostCenter;
				
				item.UniqueID = UniqueID;
				
				item.Telephone = Telephone;
				
				item.CellPhone = CellPhone;
				
				item.Email = Email;
				
				item.LastUpdatedDate = LastUpdatedDate;
				
				item.CreatedOn = CreatedOn;
				
				item.CreatedBy = CreatedBy;
				
				item.ModifiedOn = ModifiedOn;
				
				item.ModifiedBy = ModifiedBy;
				
				item.IsDeleted = IsDeleted;
				
		    item.MarkOld();
		    item.Save(UserName);
	    }

    }

}

